package cn.yunhe.controll;

import java.io.PrintWriter;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

public class BaseAction extends ActionSupport{

	/**
	 * 解耦的session
	 * 
	 * @return
	 */
	public Map<String, Object> getMapSession() {
		return ActionContext.getContext().getSession();
	}

	/**
	 * 解耦的request
	 * 
	 * @return
	 */
	public Map<String, Object> getMapRequest() {
		return (Map<String, Object>) ActionContext.getContext().get("request");
	}

	/**
	 * 耦合的request
	 * 
	 * @return
	 */
	public HttpServletRequest getRequest() {
		return ServletActionContext.getRequest();
	}

	/**
	 * 耦合的session
	 * 
	 * @return
	 */
	public HttpSession getSession() {
		return ServletActionContext.getRequest().getSession();
	}

	/**
	 * 耦合的response
	 * 
	 * @return
	 */
	public HttpServletResponse getResponse() {
		HttpServletResponse response = ServletActionContext.getResponse();
		response.setContentType("text/html; charset=UTF-8");
		return response;
	}
	/**
	 * 获得out
	 * 
	 * @return
	 */
	
	public PrintWriter getOut() {
		PrintWriter out = null;
		HttpServletResponse response = ServletActionContext.getResponse();
		
		response.setContentType("text/html; charset=UTF-8");
		try {
			out = response.getWriter();
		} catch (Exception e) {
			e.printStackTrace();
		}

		return out;

	}
}
